package com.ruoyi.order.mapper;

import com.ruoyi.order.domain.Order;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface OrderMapper {

    @Select("SELECT * FROM tb_exam_order WHERE candidate_id = #{candidateId}")
    Order selectOrderById(String candidateId);

    @Select("SELECT * FROM tb_exam_order")
    List<Order> selectOrderList();

    @Insert("INSERT INTO tb_exam_order (candidate_id, payment_status, payment_time) " +
            "VALUES (#{candidateId}, #{paymentStatus}, #{paymentTime})")
    int insertOrder(Order order);

    @Update("<script>" +
            "UPDATE tb_exam_order " +
            "<set>" +
            "<if test='paymentStatus != null'>payment_status = #{paymentStatus},</if>" +
            "<if test='paymentTime != null'>payment_time = #{paymentTime},</if>" +
            "</set>" +
            "WHERE candidate_id = #{candidateId}" +
            "</script>")
    int updateOrder(Order order);

    @Delete("DELETE FROM tb_exam_order WHERE candidate_id = #{candidateId}")
    int deleteOrderById(String candidateId);
}
